package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.goods.Spu;
import com.qingcheng.service.CreateAndDeletePage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;

/**
 * @author wyj
 * @date 2019/7/9
 */
public class CreateSpuPageMessageConsumer implements MessageListener {

    @Autowired
    private CreateAndDeletePage createAndDeletePage;


    @Override
    public void onMessage(Message message) {

        String josnStr = null;
        try {
            //设置字符集 防止出现乱码
            josnStr = new String(message.getBody(),"utf-8");
            Spu Tspu = JSON.parseObject(josnStr, Spu.class);
            createAndDeletePage.forMessage(Tspu);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
